<?php

namespace api\common\models;

use Yii;
use yii\web\IdentityInterface;

/**
 * This is the model class for table "{{%admin_user}}".
 *
 * @property integer $id
 * @property string $username
 * @property string $password
 * @property integer $type
 * @property string $project_name
 * @property string $leader
 * @property string $mobile_phone
 * @property integer $is_pc
 * @property integer $is_mobile
 * @property integer $is_check_project
 * @property integer $is_edit_project
 * @property integer $is_audit
 * @property integer $is_edit_notice
 * @property integer $is_create_account
 * @property integer $status
 * @property string $ctime
 * @property string $last_time
 * @property string $nickname
 * @property string $last_ip
 * @property string $access_token
 */
class AdminUser extends \yii\db\ActiveRecord  implements IdentityInterface
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%admin_user}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['type', 'is_pc', 'is_mobile', 'is_check_project', 'is_edit_project', 'is_audit', 'is_edit_notice', 'is_create_account', 'status'], 'integer'],
            [['ctime', 'last_time'], 'safe'],
            [['username', 'nickname', 'last_ip'], 'string', 'max' => 20],
            [['password', 'leader', 'access_token'], 'string', 'max' => 100],
            [['project_name'], 'string', 'max' => 255],
            [['mobile_phone'], 'string', 'max' => 11],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'username' => 'Username',
            'password' => 'Password',
            'type' => 'Type',
            'project_name' => 'Project Name',
            'leader' => 'Leader',
            'mobile_phone' => 'Mobile Phone',
            'is_pc' => 'Is Pc',
            'is_mobile' => 'Is Mobile',
            'is_check_project' => 'Is Check Project',
            'is_edit_project' => 'Is Edit Project',
            'is_audit' => 'Is Audit',
            'is_edit_notice' => 'Is Edit Notice',
            'is_create_account' => 'Is Create Account',
            'status' => 'Status',
            'ctime' => 'Ctime',
            'last_time' => 'Last Time',
            'nickname' => 'Nickname',
            'last_ip' => 'Last Ip',
            'access_token' => 'Access Token',
        ];
    }

    /**
     * @inheritdoc
     */
    public static function findIdentity ( $id )
    {
        return static::findOne( $id );
    }

    /**
     * @inheritdoc
     */
    public static function findIdentityByAccessToken ( $token , $type = NULL )
    {
        //throw new NotSupportedException('"findIdentityByAccessToken" is not implemented.');
        return static::findOne( [ 'access_token' => $token ] );
    }

    /**
     * @inheritdoc
     */
    public function getId ()
    {
        return $this->getPrimaryKey();
    }

    /**
     * @inheritdoc
     */
    public function getAuthKey () { }

    /**
     * @inheritdoc
     */
    public function validateAuthKey ( $authKey ) { }
}
